package indi.zhifa.study2025.oa.common.config;

import indi.zhifa.study2025.oa.common.properties.PasswdProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class AuthConfig {
    @Bean
    @ConfigurationProperties(prefix = "zhifa.auth.passwd")
    @ConditionalOnMissingBean
    public PasswdProperties passwdProperties(){
        return new PasswdProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    public PasswordEncoder passwdEncoderFactory(PasswdProperties pPasswdProperties){
        return new BCryptPasswordEncoder(pPasswdProperties.getStrength());
    }
}
